/**
 * 版权：山西书海传媒科技有限责任公司
 * 作者：吕俊雄
 * 更新时间：2019年3月29号
 */
//zx.js
//获取应用实例
const app = getApp()

Page({
  data: {
    // 分页变量
    hideBottom: true,
    page: 1,
    winHeight: 0,
    date: '2016-09-01'
  },
  onLoad: function(options) {
    // console.log(options.id);
    //初始化更多最新资讯
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 780 / clientWidth;
        var calc = clientHeight * rpxR - 80;
        console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });
    wx.request({
      url: 'https://wxapp.shuhai.cc/hh/new_messageList_less.action',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        "page": "1"
      },
      success: function(res) {
        console.log(res.data.data+ "=====ljx1");
        that.setData({
          newss: res.data.data
        })
      },
    })
  },
  bindDateChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  // 跳转资讯详情
  goID: function (e) {
    console.log(e.currentTarget.dataset.id);
    wx.navigateTo({
      url: '../zx_id/zx_id?id=' + e.currentTarget.dataset.id,
    })
  },
  // 监测搜索内容
  searchCon: function(e) {
    var that = this;
    that.data.title = e.detail.value;
  },
  //开始搜索
  seatchStart: function(e) {
    var that = this;
    wx.request({
      url: 'https://wxapp.shuhai.cc/hh/new_messageList_less_title.action',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data:{
        title: that.data.title
      },
      success: function(res) {
        console.log(res.data.data);
        that.setData({
          newss: res.data.data
        })
      },
    })
  },
  // 下拉刷新
  onPullDownRefresh() {
    // console.log('到底了')
  },
  // 这里是到底部 就加数据
  bindDownLoad: function () {
    console.log('到底部了')
    var that = this;
    // 显示加载图标
    wx.showLoading({
      title: '玩命加载中',
    })
    that.setData({
      page: that.data.page + 1,
    })
    wx.request({
      url: 'https://wxapp.shuhai.cc/hh/new_messageList_less.action?page=' + that.data.page,
      method: "post",
      // 请求头部
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        // console.log(res.data.data);
        // 设置数据
        if (JSON.stringify(res.data.data) == "{}") {
          console.log('没有了')
          // return
        } else {
          var news = that.data.newss
          // news =news.concat(res.data.data)
          for(var i = 0; i<res.data.data.length; i++){
            news.push(res.data.data[i])
          }
          that.setData({
            newss: news
          })
        }
        // 隐藏加载框
        wx.hideLoading();
      }
    })
  }
})